#!/usr/bin/env python
# 
# Quickly test various numbers of beds with a single nursing station.
# Alarm subsystems are not brought online for each bed when started this way
# to simplify testing.
#

import monitor.collector
from monitor.collector import DataCollector
import monitor.vitals
from monitor.vitals import VitalsBuffer
import monitor.alarms
from monitor.alarms import AlarmChecker
import argparse
import time

if __name__ == '__main__':

	parser = argparse.ArgumentParser(description="Start the Bed Monitor Data Collector.")
	parser.add_argument("beds", type=int, help="Number of beds to initialize")
	parser.add_argument("nurse_port", type=int, help="Port to use to connect to Nurse's station")
	parser.add_argument("port", type=int, help="Beginning of port range to use for bed subsystem communication.")
	args = parser.parse_args()

	for b in range(0, args.beds):
		collector = DataCollector(b, 5)
		vitals_buffer = VitalsBuffer(b)
		alarms_checker = AlarmChecker(b)

		base_port = args.port + (10*b)

		vitals_buffer.addListener(base_port) # from data collector
		collector.addConnector(base_port) # to vital buffer
		alarms_checker.addListener(base_port + 1) # from data collector
		collector.addConnector(base_port + 1) # to alarm system

		alarms_checker.addConnector(base_port + 3) # to bedside ui
		collector.addConnector(base_port + 2) # to bedside ui
		collector.addConnector(args.nurse_port) # nurse station
		alarms_checker.addConnector(args.nurse_port + 1)

		collector.start()
		alarms_checker.start()
		vitals_buffer.start()

		collector.register(vitals_buffer.id)
		collector.register(alarms_checker.id)
		collector.register("NURSE_1")
		collector.updateLoop()